@extends('admin::layouts.master')
@section('title')
    积分订单详情
@endsection
<style>
</style>
@section('tab')
    <div style="padding: 20px; background-color: #F2F2F2; ">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md6">
                <div class="layui-card">
                    <div class="layui-card-header">发票信息</div>
                    <div class="layui-card-body" >
                        用户头像：<img src="{{$info['user']['head_img']['full_src']}}" style="width: 80px; height: 80px;" /><br>
                        会员名称：{{$info['user']['nickname']}} <br>
                        申请类型：{{$info['type']['name']}}<br>
                        申请方式：{{$info['cate']['name']}}<br>
                        <!-- 个人 -->
                        @if( $info['type']['id'] == 1 )
                        	发票抬头：{{$info['name']}}<br>
                            电子邮箱：{{$info['email']}}<br>
                        @else  <!-- 企业 -->
                        	单位名称：{{$info['company_name']}}<br>
	                        识别码：{{$info['code']}}<br>
	                        注册地址：{{$info['apply_address']}}<br>
	                        注册电话：{{$info['phone']}}<br>
	                        开户银行：{{$info['bankname']}}<br>
                            银行账户：{{$info['bank_num']}}<br>
                            企业邮箱：{{$info['company_email']}}<br>
                        @endif
                    </div>
                </div>
            </div>
            @if( $info['cate']['id'] == 2 )
            <div class="layui-col-md6">
                <div class="layui-card">
                    <div class="layui-card-header">收货地址信息    </div>
                    <div class="layui-card-body" >
                        收货地址：{{$info['address']['province']}}{{$info['address']['city']}}{{$info['address']['area']}}{{$info['address']['address']}}<br>
                        收货姓名：{{$info['address']['username']}}<br>
                        收货电话：{{$info['address']['phone']}}<br>
                    </div>
                </div>
            </div>
            @endif

            <div class="layui-col-md6">
                <div class="layui-card">
                    <div class="layui-card-header">开票信息</div>
                    <div class="layui-card-body" >
                        @if( $info['shenqin_status'] == 2 )
                            开票状态：开票成功<br>
                            开票张数：{{$info['number']}}<br>
                            开票备注：{{$info['content']}}<br>
                        @elseif( $info['shenqin_status'] == 3 )
                            开票状态：开票失败<br>
                            开票备注：{{$info['content']}}<br>
                        @else
                            <form class="layui-form" >
                                {{ hi_form_hidden('id' ,$info['id'] ) }}
                                <div class="layui-form-item">
                                    <label class="layui-form-label"><span class="x-red">*</span>操作类型</label>
                                    <div class="layui-input-block" style="width: 300px;">
                                        <select lay-filter="shenqin_status" name="shenqin_status">
                                            <option value="">请选择操作类型</option>
                                            <option value="2">开票</option>
                                            <option value="3">暂不开票</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="layui-form-item" hidden id="num">
                                    <label for="username" class="layui-form-label">
                                        <span class="x-red">*</span>开票张数</label>
                                    <div class="layui-input-inline" style="width: 300px;">
                                        <input type="number" name="num" autocomplete="off" class="layui-input" placeholder="请输入名称"></div>
                                </div>

                                <div class="layui-form-item">
                                    <label for="username" class="layui-form-label">
                                        <span class="x-red">*</span>操作说明</label>
                                    <div class="layui-input-inline" style="width: 300px;">
                                        <textarea name="content" placeholder="请输入内容" class="layui-textarea"></textarea>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label for="username" class="layui-form-label">
                                        <a class="layui-btn layui-btn-xs" lay-filter="btn_edit" lay-submit="" >确认提交</a>
                                    </label>
                                </div>
                            </form>
                        @endif
                    </div>
                </div>
            </div>


            <div class="layui-col-md12" >
                <div class="layui-card">
                    <div class="layui-card-header">订单信息</div>
                    <table class="layui-hide" id="test" lay-filter="dataTable"></table>
                </div>
            </div>

        </div>
    </div>

    <script type="text/html" id="barDemo">  
	    <a class="layui-btn layui-btn-xs" lay-event="detail">确认开票</a>
	</script>


@endsection

@section('tab_js')
    <script>
        layui.use(['form', 'layer', 'jquery','table'], function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer,
                table = layui.table;
            table.render({
            	id:'dataTable'
                ,elem: '#test'
                ,url:'{{route("shop_invoice_goods_order",["id"=>$info["id"]])}}'
                ,height: 400
                ,cols: [[
                  ,{field:'id',  title: 'ID', sort: true, fixed: 'left'}
                  ,{field:'order_sn',  title: '订单编号'}
                  ,{field:'shop_name',  title: '门店名称'}
                  ,{field:'pay_price',  title: '开票金额'}
                  ,{field:'created_at', title: '下单时间'}
                  // ,{field:'is_invoice', title: '发票状态'}
                  // ,{field:'remark', title: '开票说明'}
                  // ,{field:'', title: '操作' , toolbar: '#barDemo'}
                ]]
                ,page: true
            });

            form.on('select(shenqin_status)',function( data ){
                if( data.value == 2 ){
                    $("#num").show();
                }else{
                    $("#num").hide();
                }
            });

            //监听提交
            var is_submit = true;
            form.on('submit(btn_edit)', function (data) {
                // if( is_submit ){
                //     return false;
                // }
                // is_submit = true;
                $.ajax({
                    url: js_url('shop-invoice-check_order'),
                    type: 'post',
                    data: data.field,
                    dataType: "json",
                    success: function (result) {
                        if (result.state === 0) {
                            layer.msg("操作成功", {time: 500, icon: 6}, function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        } else {
                            layer.msg(result.msg, {time: 2000, icon: 5});
                        }
                    }
                });
                return false;
            });

            //监听工具条
            table.on('tool(dataTable)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    ,layEvent = obj.event; //获得 lay-event 对应的值
                var order_id = data.order_id;
                var id = data.id;
                var type = data.type;
                if(layEvent === 'detail'){


                    //填写开发票的备注

                    layer.prompt({title: '请填写发票单号', formType: 3}, function(content, index){
                        $.ajax({
                            url: js_url('shop-invoice-check_order'),
                            type: 'post',
                            data: {id:id,invoice_number:content,'type':2},
                            dataType: "json",
                            success: function (result) {
                                if (result.state === 0) {
                                    layer.msg(result.msg, {time: 1000, icon: 1}, function () {
                                        window.parent.location.reload()//刷新父页面
                                    });
                                } else {
                                    layer.msg(result.msg, {time: 2000, icon: 5});
                                }
                            }
                        });
                    });
                }
            });
        })




       </script>
@endsection      
